<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
[#include "/admin/include/head.htm"]
<script type="text/javascript">
	var grid;
	var hasTipDialog = false;
	var tipDialog;
	var dialogTimeout;
	$(function(){
		 grid = $("#maingrid").ligerGrid({
            columns: [
			{name: 'id', hide: true, width:0, isAllowHide: false},
			{name: 'isExpired', hide: true, width:0, isAllowHide: false},
			{display: '订单号',name:'orderNo' ,align: 'center', width: 150, render: function (row, rowindex, value, column){
				if (row["id"]) {
					var html = '<a style="color:blue" href="#" onMouseOut="closeTipDialog(\'' + row.id + '\',\'' + row.orderNo + '\'); return false;"  onMouseOver="showTipDialog(this,event,\'' + row.id + '\',\'' + row.orderNo + '\'); return false;">'+value+'</a>';
					return html;
				}
            }},
			{display: '创建时间', name: 'createDate', align: 'center', width: 140, dataFormat: 'yyyy-MM-dd HH:mm:ss'},
			{display: '订单金额', name: 'amount', align: 'center', width: 80},
			{display: '使用余额', name: 'amount', align: 'center', width: 80},
			{display: '订单金额', name: 'amount', align: 'center', width: 80},
			{display: '会员名称', name: 'member.username', align: 'center', width: 120},
			{display: '支付类型', name: 'payType', i18n:'PayType', align: 'center', width:80},
			{display: '支付方式', name: 'paymentTypeName', align: 'left', width:80},
			{display: '订单状态', name: 'orderStatus', i18n:'orderStatus', align: 'left', width: 130, 
				render: function(row){
					if(row.isExpired == "true"){
						return row.orderStatus + "[已过期]";
					}
					return row.orderStatus;
				}
			},
			{display: '支付状态', name: 'payStatus', i18n:'PayStatus', align: 'center', width: 80 },
			{display: '发货状态', name: 'shipStatus', i18n:'ShipStatus', align: 'center', width: 80 },
			{display: '打印', name: 'clickNumber', align: 'center', width: 90,render: function(row){
					if (row["id"]) {
						var html = '<select onchange="print(this,\'' + row.id + '\',\'' + row.orderNo + '\',' + (row.rejectState != undefined && row.rejectState != '') +')"><option value="">请选择...</option>'
								+ '<option value="express">快递单</option></select>';
						return html;
					}
				} 
			}
			], pageSize:20,url: 'queryData.jhtml', toolbar: {}, width: '100%', height:'100%'
        });
        $("#pageloading").hide();
		LG.loadToolbar(grid);
		
		//绑定搜索按钮
		LG.search(grid);
	});

	function showTipDialog(target, e , id, orderNo) {
		if(hasTipDialog) {
			window.clearTimeout(dialogTimeout);
			$.ligerDialog.close();
			hasTipDialog = false;
		}
		var offset = $(target).offset();
		var bodyWidth= $(document.body).width();
		var bodyHeight = $(document.body).height();
		var top = offset.top + 15;
		if(top + 350 > bodyHeight) {
			top = (offset.top + 25) - 350; 
		}
		window.setTimeout(function() {
			$.ligerDialog.open({ 
				id: 'tipDialog',
				width: bodyWidth - (offset.left + 20)-200, 
				height: 500,
				top: top,
				left: offset.left + 50,
				url:'items.jhtml?id='+ id,
				isDrag : false, 
				modal: false,
				title: '商品信息'
			});
			hasTipDialog = true;
			document.getElementById('tipDialog').onmouseover = function() {
				window.clearTimeout(dialogTimeout);
			};
			document.getElementById('tipDialog').onmouseout = function() {
				closeTipDialog();
			};
		}, 80);
	}
	
	function closeTipDialog() {
		dialogTimeout = window.setTimeout(function() {
			$.ligerDialog.close();
			hasTipDialog = false;
		}, 150);
	}

	function detail(){
		var selecteds = grid.getSelecteds();
    	if (selecteds.length != 1) { 
    		LG.tip('请选择一行记录!'); 
    		return; 
    	}
    	var id = selecteds[0].id;
		if(top.f_isTabItemExist("order" + id)){
			top.f_switchTab("order" + id);
		}else{
			top.f_addTab("order" + id, "订单" + selecteds[0].orderNo, base + '/admin/b2c/order/detail.jhtml?id=' + id + '&parentMenuNo=order_list');
		}
	}
	function f_delete() {//删除
      var selecteds = grid.getSelecteds();
      if (selecteds.length > 0) {
		  var arr = [];
		  for(var i = 0;i < selecteds.length;i++){
		  	arr.push(selecteds[i].id);
		  }
          LG.ajax({
          	  url: base + '/admin/b2c/order/delete.jhtml',
              loading: '正在删除中...',
              data: { ids: arr.join(',') },
              success: function () {
                  LG.showSuccess('删除成功');
                  f_reload();
              },
              error: function (message) {
                  LG.showError(message);
              }
          });
      } else {
          LG.tip('请选择行!');
      }
   }	
	
	function swithSearch(obj){
		if(obj.innerHTML == '高级查询'){
			$("#superSearch").css("display", 'block');
			obj.innerHTML = '取消高级查询';
		}else{
			$("#superSearch input").each(function(i,item){
				item.value = '';
			});
			$("#superSearch").css("display", 'none');
			$("#receiver").val('');
			$("#startTime").val('');
			$("#endTime").val('');
			obj.innerHTML = '高级查询';
		}
	}
	
	function print(obj,id,orderNo,needSelect){
		if(obj.value == ''){
			return;
		}
		if(top.f_isTabItemExist(obj.value + "print" + id)){
			top.f_switchTab(obj.value + "pint" + id);
		}else{
			var url = base;
			if(obj.value == 'express'){
				url = url + '/admin/b2c/print/delivery.jhtml?orderId=' + id;
			}
			top.f_addTab(obj.value + "pint" + id, "订单【" + orderNo + "】" + obj[obj.selectedIndex].text + "打印", url);
		}
	}
</script>
</head>
<body style="padding:10px; overflow:hidden;">		
	<div id="functions">
		<div class="clearfix">
			<div>
				<span>
					订单状态：[@u.select_map headerKey="" headerValue="全部"
					listKey="key" listValue="name"
					headerButtom="false" list=orderStatusList
					name="search_EQ_orderStatus"/]
				</span>
				<span>
					支付类型：[@u.select_map headerKey="" headerValue="全部"
					listKey="key" listValue="name"
					headerButtom="false" list=payTypeList
					name="search_EQ_payType"/]
				</span>
				<span>
					支付状态：[@u.select_map headerKey="" headerValue="全部"
					listKey="key" listValue="name"
					headerButtom="false" list=payStatusList
					name="search_EQ_payStatus"/]
				</span>
				<span>
					门店：[@u.select_map headerKey="" headerValue="全部"
				listKey="id" listValue="name"
				headerButtom="false" list=storeList
				name="search_EQ_store.id"/]
				</span>
				<input type="button" class="button" value="查询" id="search"/>
				<a href="#" onclick="swithSearch(this)">高级查询</a>
				<a href="#" id="search_btn_reset" face="Wingdings 3">清除本次搜索</a>
			</div>
			<br/>
			<div id="superSearch" style="display:none;">
				<span>
					会员名：<input style="width: 150px" name="search_EQ_member.username" type="text" class="formText">
				</span>
				<span>
					订单编号：<input style="width: 150px" name="search_EQ_orderNo"  type="text" class="formText"/>
				</span>
				<span>
					下单时间：<input type="text" name="search_GE_createDate" class="formText WdatePicker {dateFmt:'yyyy-MM-dd'}"/>
					- <input type="text" name="search_LE_createDate" class="formText WdatePicker {dateFmt:'yyyy-MM-dd'}"/>
					
				</span>
			</div>
		</div>
	</div>	
	<div id="maingrid" style="margin:0; padding:0"> </div>
</body>
</html>